package org.example;

public class Result<T> {
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public static int getSUCCESS() {
        return SUCCESS;
    }

    public static int getERROR() {
        return ERROR;
    }

    private int code;
    private String message;
    private boolean success;

    private static final int SUCCESS=200;
    private static final int ERROR=600;

    public Result(T data, int code, String message, boolean success) {
        this.data = data;
        this.code = code;
        this.message = message;
        this.success = success;
    }
    public static Result Error(int code, String message){
       Result result=new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        result.setSuccess(false);
        return result;
    }
    public static Result Error(){
       Result result=new Result();
        result.setCode(ERROR);
        result.setMessage("error");
        result.setData(null);
        result.setSuccess(false);
        return result;
    }
    public static Result Success(Object data){
       Result result=new Result();
        result.setCode(SUCCESS);
        result.setMessage("ok");
        result.setData(data);
        result.setSuccess(true);
        return result;
    }
    public static Result Success(){
      Result result=new Result();
        result.setCode(SUCCESS);
        result.setMessage("ok");
        result.setData(null);
        result.setSuccess(true);
        return result;
    }

    public Result(){

    }

}
